*prepare main data first
clear
use complete_main_new
sort countryid year
tsset countryid year

quietly gen conflict = bdbest1000

generate one_before=conflict==0&F1.conflict==1
generate one_after=conflict==0&L1.conflict==1
generate two_before=conflict==0&(F1.conflict==1|F2.conflict==1)

quietly gen conflict25 = bdbest25

generate one_before25=conflict25==0&F1.conflict25==1

keep countryid year pop country *before *conflict* one_after one_before25

sort countryid year

save output/temp, replace




*use the topic similarity data created with another do file (topic wordlist?)
use found_topics, clear

generate name1 = "topic"
generate name2 = "topic"

*from staring at it
replace name1 = "industry" if year2==2013 & topic2==0
replace name1 = "civlife" if year2==2013 & topic2==1
replace name1 = "asia" if year2==2013 & topic2==2
replace name1 = "sports" if year2==2013 & topic2==3
replace name1 = "justice" if year2==2013 & topic2==4
replace name1 = "tourism" if year2==2013 & topic2==5
replace name1 = "politics" if year2==2013 & topic2==6
replace name1 = "conflict1" if year2==2013 & topic2==7
replace name1 = "business" if year2==2013 & topic2==8
replace name1 = "economics" if year2==2013 & topic2==9
replace name1 = "int_relations2" if year2==2013 & topic2==10
replace name1 = "int_relations1" if year2==2013 & topic2==11
replace name1 = "conflict3" if year2==2013 & topic2==12
replace name1 = "civlife2" if year2==2013 & topic2==13
replace name1 = "conflict2" if year2==2013 & topic2==14

generate id = .

replace id = 0 if year2==2013 & topic2==0
replace id = 1 if year2==2013 & topic2==1
replace id = 2 if year2==2013 & topic2==2
replace id = 3 if year2==2013 & topic2==3
replace id = 4 if year2==2013 & topic2==4
replace id = 5 if year2==2013 & topic2==5
replace id = 6 if year2==2013 & topic2==6
replace id = 7 if year2==2013 & topic2==7
replace id = 8 if year2==2013 & topic2==8
replace id = 9 if year2==2013 & topic2==9
replace id = 10 if year2==2013 & topic2==10
replace id = 11 if year2==2013 & topic2==11
replace id = 12 if year2==2013 & topic2==12
replace id = 13 if year2==2013 & topic2==13
replace id = 14 if year2==2013 & topic2==14

keep year1 topic1 name1 id
rename year1 year
rename topic1 topic
rename name1 name
saveold output/topicnames_hm.dta, replace




local y=2013
use "thetas15_alpha3_beta001_all_both_collapsed`y'.dta", clear
forvalues t=0/14 {
generate topic`t' = ste_theta`t'
}

merge 1:1 countryid year using output/temp.dta


bysort countryid: egen avpop=mean(pop)											
drop if avpop==.
drop if avpop<1000										


tsset countryid year

*TABLE G.2
*analysis of how all topics change with armed conflict
xtreg topic0 one_before25 conflict25, fe
outreg2 using output/dynamics_ac, replace
foreach var of varlist topic1 topic2 topic3 topic4 topic5 topic6 topic8 topic9 topic10 topic11 topic13  {
xtreg `var' one_before25 conflict25, fe
outreg2 using output/dynamics_ac, excel
}

*analysis of how all topics change with civil war
xtreg topic0 one_before conflict, fe
outreg2 using output/dynamics_cw, replace
foreach var of varlist topic1 topic2 topic3 topic4 topic5 topic6 topic8 topic9 topic10 topic11 topic13  {
xtreg `var' one_before conflict, fe
outreg2 using output/dynamics_cw, excel
}


*TABLE G.3
*make a table that shows how conflict topics move around start
xtreg topic7 one_before25 conflict25, fe
outreg2 using output/dynamics_co, replace
foreach var of varlist topic14 topic12  {
xtreg `var' one_before25 conflict25, fe
outreg2 using output/dynamics_co, excel
}

xtreg topic7 one_before conflict, fe
outreg2 using output/dynamics_co
foreach var of varlist topic14 topic12  {
xtreg `var' one_before conflict, fe
outreg2 using output/dynamics_co, excel
}








